<template>
  <div class="app-container">
    <el-input placeholder="输入关键字进行过滤" v-model="filterText"> </el-input>

    <el-tree
      class="filter-tree"
      :data="data"
      :props="defaultProps"
      default-expand-all
      :filter-node-method="filterNode"
      ref="tree"
    >
    </el-tree>
  </div>
</template>

<script>
import { getAllSubject } from '@/api/edu/subject'
export default {
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    this.getAllSubjectList()
  },
  methods: {
    async getAllSubjectList() {
      const res = await getAllSubject()

      this.data = res.data.list
    },
    filterNode(value, data) {
      if (!value) return true
      // return data.label.indexOf(value) !== -1
      return data.title.toLowerCase().indexOf(value.toLowerCase()) !== -1
    }
  },

  data() {
    return {
      filterText: '',
      data: null,
      defaultProps: {
        children: 'children',
        // label: 'label'
        label: 'title'
      }
    }
  }
}
</script>
